package com.indobrains.uud1945;

import com.indobrains.uud1945.database.DatabaseAdapter;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;

public class PasalActivity extends ListActivity {
	private static final String TAG = "Clauses";
	private static final String CHAPTER_ID = "_id";
	private static final String CHAPTER_TITLE = "title";
	private ListView lv;
	private DatabaseAdapter db;
	private Cursor cursor;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chapter_layout);
		TextView title=(TextView)findViewById(R.id.title);
		
		Bundle b = getIntent().getExtras();
		int chapter_id=b.getInt(CHAPTER_ID);
		title.setText(b.getString(CHAPTER_TITLE));
		Log.d(TAG,"Chapter id : "+Integer.toString(chapter_id));
		 
		
		lv=getListView();
		setClauseAdapter(lv, chapter_id);
	}
	public void setClauseAdapter(ListView view,int chapter_id){
		try {
			db=new DatabaseAdapter(this);
			db.Open();
			cursor=db.getClauses(chapter_id);
			startManagingCursor(cursor);
			String[] from = new String[] {db.CLAUSE_ID, db.CLAUSE_TITLE,db.AMANDEMEN_DESC };
			int[] to = new int[] {R.id.clause_id, R.id.ClauseTitle,R.id.ClauseAmandemen};
			//MenuAdapter adapter=new MenuAdapter(getActivity(), R.layout.list_item, cursor, from, to);
			PasalAdapter adapter = new PasalAdapter(this,R.layout.pasal_item,cursor,from,to);
			//DasarHukumAdapter adapter=new DasarHukumAdapter(this,R.layout.dasar_hukum,cursor,from,to);
			view.setAdapter(adapter);
			//setListAdapter(adapter);
		} catch (Exception ex){
			Log.e(TAG,ex.getMessage());
		}
	}
}
